home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / valimp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  6.7 KB  |  292 lines

  1. #ifndef __RW_VALIMP__
  2. #define __RW_VALIMP__
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * valimp - Declarations for the Standard Library valarray
  8.  *
  9.  * $Id: valimp,v 1.1 1996/09/25 00:47:35 philippe Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  * 
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44.  
  45. #include <stdcomp.h>
  46.  
  47. #ifndef _RWSTD_NO_NEW_HEADER
  48. #include <cstddef>
  49. #include <cstring>
  50. #else
  51. #include <stddef.h>
  52. #include <string.h>
  53. #endif
  54.  
  55. #include <rw/math.h>
  56.  
  57. //#define _RWSTD_NO_IMP_NAMESPACE 1  
  58.  
  59. #ifndef _RWSTD_NO_NAMESPACE
  60. namespace std { }
  61.  #ifndef _RWSTD_NO_IMP_NAMESPACE
  62.   namespace rwstd {
  63.   #define _RW_IMP_SPACE(name) ::rwstd::name
  64.   using namespace std;
  65.  #else
  66.   namespace std {
  67.   #define _RW_IMP_SPACE(name) ::std::name
  68.  #endif
  69. #else
  70. #define _RW_IMP_SPACE(name) name
  71. #endif
  72.  
  73.  
  74.  
  75. /****************************************************************
  76. *               IMPLEMENTATION FUNCTIONALITIES                  *
  77. *                                                               *
  78. *   - valarray memory model                                     *
  79. *   - valarray optimization on copy and return                  *
  80. *                                                               *
  81. ****************************************************************/
  82.  
  83.  
  84. // valarray_traits class
  85. // allow memory optimization 
  86. // for builtin types and user types
  87.  
  88. template <class T> 
  89. class valarray_traits_optimize 
  90. {
  91.  public:
  92.  
  93.   static bool optimize_copy() { return false; }
  94. };
  95.  
  96.  
  97. #ifndef _RWSTD_NO_BOOL
  98. _RWSTD_TEMPLATE
  99. class valarray_traits_optimize<bool>
  100. {
  101.  public:
  102.  
  103.   static bool optimize_copy() { return true; }
  104. };
  105. #endif
  106.  
  107. _RWSTD_TEMPLATE
  108. class valarray_traits_optimize<short>
  109. {
  110.  public:
  111.  
  112.   static bool optimize_copy() { return true; }
  113. };
  114.  
  115. _RWSTD_TEMPLATE
  116. class valarray_traits_optimize<unsigned short>
  117. {
  118.  public:
  119.  
  120.   static bool optimize_copy() { return true; }
  121. };
  122.  
  123. _RWSTD_TEMPLATE
  124. class valarray_traits_optimize<int>
  125. {
  126.  public:
  127.  
  128.   static bool optimize_copy() { return true; }
  129. };
  130.  
  131. _RWSTD_TEMPLATE
  132. class valarray_traits_optimize<unsigned int>
  133. {
  134.  public:
  135.  
  136.   static bool optimize_copy() { return true; }
  137. };
  138.  
  139. _RWSTD_TEMPLATE
  140. class valarray_traits_optimize<long>
  141. {
  142.  public:
  143.  
  144.   static bool optimize_copy() { return true; }
  145. };
  146.  
  147. _RWSTD_TEMPLATE
  148. class valarray_traits_optimize<unsigned long>
  149. {
  150.  public:
  151.  
  152.   static bool optimize_copy() { return true; }
  153. };
  154.  
  155. _RWSTD_TEMPLATE
  156. class valarray_traits_optimize<float>
  157. {
  158.  public:
  159.  
  160.   static bool optimize_copy() { return true; }
  161. };
  162.  
  163. _RWSTD_TEMPLATE
  164. class valarray_traits_optimize<double>
  165. {
  166.  public:
  167.  
  168.   static bool optimize_copy() { return true; }
  169. };
  170.  
  171. _RWSTD_TEMPLATE
  172. class valarray_traits_optimize<long double>
  173. {
  174.  public:
  175.  
  176.   static bool optimize_copy() { return true; }
  177. };
  178.  
  179. _RWSTD_TEMPLATE
  180. class valarray_traits_optimize<char>
  181. {
  182.  public:
  183.  
  184.   static bool optimize_copy() { return true; }
  185. };
  186.  
  187. _RWSTD_TEMPLATE
  188. class valarray_traits_optimize<unsigned char>
  189. {
  190.  public:
  191.  
  192.   static bool optimize_copy() { return true; }
  193. };
  194.  
  195.  
  196. // for optimization on return of
  197. // valarray<T> values
  198.  
  199. template <class T>
  200. struct _RW_temporary {
  201.  
  202.         T*      store_adr;
  203.         size_t  length;
  204.     };
  205.  
  206.  
  207. // Class _RW_array<T>
  208. // C type array storage class
  209. // responsible for physical representation
  210. // of the valarray in memory and memory operations
  211.  
  212. template <class T> class _RW_array {
  213.  
  214. public:
  215.  
  216.     _RW_array( )
  217.     : _RW_length(0)
  218.     , _RW_storage(0)
  219.     { ; }
  220.  
  221.     ~_RW_array( )
  222.     { if ( _RW_storage ) delete []_RW_storage; }
  223.  
  224.     void _initial_size(size_t size)
  225.     {
  226.       _RW_length = size;
  227.       _RW_storage = new T[_RW_length];
  228.     }
  229.  
  230.     void _initialize_with_value(const T&, size_t);
  231.     void _initialize_with_array(const T*, size_t);
  232.     void _copy_memory_array(const _RW_array<T>&);
  233.  
  234.     size_t _get_length() const { return _RW_length; }
  235.  
  236.     T operator[] (size_t ind) const
  237.     { return _RW_storage[ind]; }
  238.  
  239.     T& operator[] (size_t ind)
  240.     { return _RW_storage[ind]; }
  241.  
  242.     void _replace(T* tmp_adr, size_t tmp_length )
  243.     {
  244.        _RW_storage = tmp_adr;
  245.        _RW_length = tmp_length;
  246.     }
  247.  
  248.     T* _RW_get_storage() const { return _RW_storage; }
  249.  
  250.     void _RW_invalidate()
  251.     {
  252.       _RW_length = 0;
  253.       _RW_storage = 0;
  254.     }
  255.  
  256.     void _RW_copy( T* pointer ) const
  257.     {
  258.        memcpy( (void*)pointer, (void*)_RW_storage, _RW_length*sizeof(T));
  259.     }
  260.  
  261.     void _RW_resize_without_copy( size_t size)
  262.     {
  263.        if ( _RW_storage )
  264.     {
  265.       delete []_RW_storage;
  266.           _RW_storage = 0;
  267.         }
  268.             _RW_length = size;
  269.         if ( size > 0 ) _RW_storage = new T[_RW_length];
  270.     }
  271.  
  272. private:
  273.  
  274.     size_t                         _RW_length;
  275.     T*                             _RW_storage;
  276.  
  277. };
  278.  
  279.  
  280. #ifndef _RWSTD_NO_NAMESPACE
  281. }
  282. #endif
  283.  
  284.  
  285. #ifdef _RWSTD_NO_TEMPLATE_REPOSITORY
  286. #include <rw/valimp.cc>
  287. #endif
  288.  
  289. #pragma option pop
  290. #endif /* __RW_VALIMP__ */
  291.  
  292.